<?php
defined('IN_TS') or die('Access Denied.');

$wishid = intval($_GET['id']);
//心愿信息
$strWish = $new['wish']->find('wish',array(
	'wishid'=>$wishid,
));

if($strWish==''){
	header ( "HTTP/1.1 404 Not Found" );
	header ( "Status: 404 Not Found" );
	$title = '404';
	include pubTemplate ( "404" );
	exit ();
}


if($strWish['isaudit']==1 && $TS_USER['isadmin']==0 || $strWish['isaudit']==1 && $strWish['userid']!=$TS_USER['userid'] && $TS_USER['isadmin']==0){
	tsNotice('心愿审核中...');
}

$strWish['title'] = tsTitle($strWish['title']);
$strWish['address'] = tsTitle($strWish['address']);
$strWish['content'] = tsDecode($strWish['content']);
$strWish['coordinate'] = tsTitle($strWish['coordinate']);

$strWish['user'] = aac('user')->getOneUser($strWish['userid']);
$strWish['group'] = aac('group')->getOneGroup($strWish['groupid']);
$strWish['type'] = $new['wish']->find('wish_type',array(
	
	'typeid'=>$strWish['typeid'],

));

$cover =tsXimg($strWish['photo'],'wish',500,'',$strWish['path']);
// 是否点赞

$isRecommend = $new['wish']->findCount ( 'wish_recommend', array (
	'wishid' => $wishid,
	'userid' => $userid
) );


//wishdo
$isWishUser = 0;
if($TS_USER['userid']){
	
	$userid = $TS_USER['userid'];
	

	$strWishUser = $new['wish']->find('wish_users',array(

		'wishid'=>$strWish['wishid'],
		'userid'=>$userid,

	));

	
}


//申领这个心愿的成员
$arrDoUsers = $new['wish']->findAll('wish_users','wishid='.$strWish['wishid'].' and status>-1','addtime desc');

foreach($arrDoUsers as $key=>$item){
	$arrDoUser[] = $item;
	if(aac('user')->isUser($item['userid'])){
		$arrDoUser[$key]['user'] = aac('user')->getOneUser($item['userid']);
	}
}


$remain = $strWish['quota']-$strWish['count_userwish'];

//评论

$page = isset($_GET['page']) ? intval($_GET['page']) : 1;

$url = tsUrl('wish','show',array('id'=>$wishid,'page'=>''));

$lstart = $page*10-10;

$arrComments = $new['wish']->findAll('wish_comment',array(
	'wishid'=>$strWish['wishid'],
),'addtime desc',null,$lstart.',10');

foreach($arrComments as $key=>$item){
	if(aac('user')->isUser($item['userid'])){
		$arrComment[$key] = $item;
		$arrComment[$key]['content'] = tsDecode($item['content']);
		$arrComment[$key]['user'] = aac('user')->getOneUser($item['userid']);
	}
}

$commentNum = $new['wish']->findCount('wish_comment',array(
	'wishid'=>$strWish['wishid'],
));

$strTopic = aac('group')->find('group_topic',array(
	'topicid'=>232,
));
$strTopic['content'] = tsDecode($strTopic['content'],$tp);

$notice = '认领成功，感谢您的善意！<br/>您有两天的时间可以用来寻购、下单、发货！<br/>发货后请点击下方按钮填写快递单号。<br/>';

$pageUrl = pagination($commentNum, 10, $page, $url);

$title = $strWish['group']['groupname'].$strWish['wisher'].'的心愿：'.$strWish['title'];
include template("show");